/*
js操作class
 */
export default {
  hasClass (ele, cls) {
    cls = cls || ''
    if (cls.replace(/\s/g, '').length === 0) return false // 当cls没有参数时，返回false
    return new RegExp(' ' + cls + ' ').test(' ' + ele.className + ' ')
  },
  addClass (ele, cls) {
    if (!this.hasClass(ele, cls)) {
      ele.className = ele.className === '' ? cls : ele.className + ' ' + cls
    }
  },
  removeClass (ele, cls) {
    if (this.hasClass(ele, cls)) {
      let newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' '
      while (newClass.indexOf(' ' + cls + ' ') >= 0) {
        newClass = newClass.replace(' ' + cls + ' ', ' ')
      }
      ele.className = newClass.replace(/^\s+|\s+$/g, '')
    }
  },
  // 根据单元格结点获取其所在行号
  getRowId (cell) {
    let currRow = cell.parentNode
    let tbody = currRow.parentNode
    var lists = Array.from(tbody.querySelectorAll('tr'))
    return lists.indexOf(currRow)
  }
}
